//
//  HomeStyleFirstCell.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/5/12.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "HomeStyleFirstCell.h"
#import <UIImageView+WebCache.h>
#import "HomeGoodsTypeModel.h"

@interface HomeStyleFirstCell()

@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UIButton *subTitleBtn;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UIButton *firstTypeBtn;
@property (weak, nonatomic) IBOutlet UIButton *secondTypeBtn;
@property (weak, nonatomic) IBOutlet UIButton *thirdTypeBtn;
@property (weak, nonatomic) IBOutlet UIButton *fouthTypeBtn;


@end

@implementation HomeStyleFirstCell

- (void)awakeFromNib {
    [super awakeFromNib];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
    [self.iconImageView addGestureRecognizer:tap];
}
- (void)tapClick
{
    [self typeClick:self.subTitleBtn];
}

- (void)setModel:(HomeGoodsModel *)model
{
    _model = model;
    self.nameLab.text = model.recommendName;
    [self.subTitleBtn setTitle:[NSString stringWithFormat:@"%@ ＞",model.subtitle] forState:UIControlStateNormal];
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.indexActivityImage] placeholderImage:GetImage(@"firstPlace")];
    for (NSInteger i = 0; i < 4; i++) {
        if (model.typeList.count<i+1) return;
        HomeGoodsTypeModel *typeModel = model.typeList[i];
        if (i == 0) {
            [self.firstTypeBtn setTitle:typeModel.productTypeName forState:UIControlStateNormal];
        }else if (i == 1) {
            [self.secondTypeBtn setTitle:typeModel.productTypeName forState:UIControlStateNormal];
        }else if (i == 2) {
            [self.thirdTypeBtn setTitle:typeModel.productTypeName forState:UIControlStateNormal];
        }else if (i == 3) {
            [self.fouthTypeBtn setTitle:typeModel.productTypeName forState:UIControlStateNormal];
        }
    }
}
- (IBAction)typeClick:(UIButton *)btn
{
    HomeGoodsTypeModel *typeModel;
    if (btn.tag == 0) {
        typeModel = [[HomeGoodsTypeModel alloc]init];
        typeModel.ID = self.model.productTypeParentId;
        typeModel.productTypeName = self.model.productTypeName;
    }else {
        typeModel = self.model.typeList[btn.tag-1];
    }
    if (self.typeClickBlock) {
        self.typeClickBlock(typeModel);
    }
}

@end
